<?php
namespace app\common\model;

class Product extends \think\Model
{
    public function fillProduct($id, $name, $cover, $cat, $status, $sort)
    {
        if (is_null($id) || strlen($id) == 0) {
            $id = uniqid();
        }
        $model = ['id' => $id, 'name' => $name, 'cover' => $cover, 'cat' => $cat, 'status' => $status, 'sort' => $sort];
        return $model;
    }
    /** 获取一个产品 */
    public function getProductInfo($id)
    {
        $model = $this->getProductInfo($id, '测试商品', 'http://www.baidu.com', '分类的id', 1, 10);
        return $model;
    }
    /** 获取产品列表 */
    public function getProductList($kind, $keyword, $status)
    {
        $lst = array();

        array_push($lst, $this->getProductInfo(uniqid()));
        array_push($lst, $this->getProductInfo(uniqid()));

        return $lst;
    }
    /** 创建一个产品 */
    public function createProduct($model)
    {
        return ['flag' => \FALSE, 'msg' => '此方法未实现'];
    }
    /** 修改产品 */
    public function updateProduct($id, $model)
    {
        return ['flag' => \FALSE, 'msg' => '此方法未实现'];
    }
    /** 删除一个产品 */
    public function removePrdouct($id)
    {
        return ['flag' => \FALSE, 'msg' => '此方法未实现'];
    }

    /** 以下是产品分类 */

    /** 封装一个产品分类 */
    public function fillCategory($id, $cids, $parents, $name, $cover, $status, $sort)
    {
        $model = ['id' => $id, 'cids' => $cids, 'parents' => $parents, 'name' => $name, 'cover' => $cover, 'status' => $status, 'sort' => $sort];
        return $model;
    }
    /** 获取一个产品分类 */
    public function getCategory($id)
    {
        $model = $this->fillCategory($id, 'c1', '', '产品分类一', 'http://www.baidu.com/category.png', 1, 1);
        return $model;
    }
    /** 获取产品分类列表 */
    public function getCategoryList($keyword, $parent, $status, $take, $pages)
    {
        $lst = array();

        array_push($lst, $this->getCategory(1));
        array_push($lst, $this->getCategory(2));
        array_push($lst, $this->getCategory(3));

        return $lst;
    }
    /** 创建一个产品分类 */
    public function createCategory($model)
    {
        return ['flag' => \FALSE, 'msg' => '此方法未实现'];
    }
    /** 修改产品分类 */
    public function updateCategory($id, $model)
    {
        return ['flag' => \FALSE, 'msg' => '此方法未实现'];
    }
    /** 删除一个产品分类 */
    public function removeCategory($id)
    {
        return ['flag' => \FALSE, 'msg' => '此方法未实现'];
    }
}